﻿using BookTheBook.Data.Model;
using BookTheBook.Data.NameDefinitions;
using FluentNHibernate.Mapping;

namespace BookTheBook.Data.Mappings
{
    public class UserMap : ClassMap<User>
    {
        public UserMap()
        {
            Table(TableNames.User);
            Id(x => x.Id).Column(ColumnNames.UserId);
            Map(x => x.Login).Column(ColumnNames.Login);
            HasMany(x => x.RentedBooks).Inverse().Cascade.All().Table(TableNames.RentDetails).KeyColumn(ColumnNames.UserId);
            HasManyToMany(x => x.Roles).Inverse().Table(TableNames.RoleToUser).
                                                  ParentKeyColumn(ColumnNames.UserId).
                                                  ChildKeyColumn(ColumnNames.RoleId);
        }
    }
}
